package com.sh.data.engine.application.model.request.integration;

import com.sh.data.engine.application.model.annotation.DataSourceConditionalFields;
import com.sh.data.engine.common.enumDefinition.DSType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import java.util.Date;
import java.util.List;

/**
 * @author: mengzheng.mhc
 * @date: 2024/12/17 17:02
 */
@Data
@Schema
@DataSourceConditionalFields
public class DataSourceCreateRequest {

    /**
     * 数据库模式
     */
    @Schema(description = "datasource schema")
    private String schema;
    private Date createTime;
    private String creatorId;
    private Date updateTime;
    private String updaterId;

    @Schema(description = "数据源Id")
    private Long id;

    @Schema(
            description = "数据源名称",
            requiredMode = Schema.RequiredMode.REQUIRED,
            minLength = 2,
            maxLength = 32,
            pattern = "[a-zA-Z0-9_\\u4e00-\\u9fa5]+")
    @Length(min = 2, max = 32, message = "数据源名称长度在2-32个字符")
    @Pattern(regexp = "[a-zA-Z0-9_\\u4e00-\\u9fa5]+", message = "数据源名称支持中文、字母、数字和下划线")
    private String dsName;

    @Schema(description = "数据源类型", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "数据源类型不能为空")
    private DSType dsType;

    @Schema(description = "描述", maxLength = 128)
    @Length(max = 128, message = "描述长度不能超过128个字符")
    private String dsDesc;

    @Schema(description = "数据源配置")
    private DataSourceCreateRequest.DSConfig dsConfig;

    @Data
    @Schema
    public static class DSConfig {

        /**
         * hdfs的用户
         */
        private String hdfsUser;
        /**
         * 链接地址
         */
        @Schema(description = "链接地址")
        private String dsLink;

        @Schema(description = "用户名")
        private String username;

        @Schema(description = "密码")
        private String password;

        @Schema(description = "主机")
        private String server;

        @Schema(description = "端口", minimum = "0", maximum = "65535")
        @Min(value = 0, message = "端口不能小于0")
        @Max(value = 65535, message = "端口不能大于65535")
        private Integer port;

        @Schema(description = "地址")
        private List<Address> address;

        @Schema(description = "数据库")
        private String dbName;

        @Schema(description = "API Token")
        private String apiToken;

        @Schema(description = "组织名称")
        private String orgName;

        @Schema(description = "连接属性")
        private String connectionProperty;

        @Schema(description = "hive-site.xml文件上传位置")
        private String hiveSiteAddress;

        @Schema(description = "hive-site.xml文件原始名")
        private String originalFilename;

        @Schema(description = "权限检验空间", defaultValue = "admin")
        private String authDbName;

        @Schema(description = "oracle数据库连接类型 0-sid 1-service name")
        private Integer oracleConnectionType;
    }

    @Data
    @Schema
    public static class Address {

        @Schema(description = "主机")
        private String host;

        @Schema(description = "端口", minimum = "0", maximum = "65535")
        @Min(value = 0, message = "端口不能小于0")
        @Max(value = 65535, message = "端口不能大于65535")
        private Integer port;
    }
}
